import Koa from 'koa';
import Router from 'koa-router';
import bodyParser from 'koa-bodyparser';
import cors from '@koa/cors';
import { appPort } from './config/setting.js';
import { registerRouter } from './router/bookRouter.js';
import { sync } from './model/Book.js';


const app = new Koa()
const router = new Router()

//解析前端数据
app.use(bodyParser())

//注册路由
registerRouter(router)

//解决跨域
app.use(cors())

//同步数据库
sync()

//自动注册路由
app.use(router.routes())


//监听
app.listen(appPort)

console.log(`服务器运行地址为:http://localhost:${appPort}`);



